<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline" style="padding-left: 5px;">
                <input type="text" name="user_name" lay-verify="title" placeholder="User Name" autocomplete="off"
                       class="layui-input">
        </div>
        <div class="layui-inline" style="padding-left: 5px;">
                <input type="text" name="card_num" lay-verify="title" placeholder="Card Num" autocomplete="off"
                       class="layui-input">
        </div>
        <div class="layui-inline" style="padding-left: 5px;">
            <input type="text" name="shopping" lay-verify="title" placeholder="商家" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-inline" style="padding-left: 5px;">
            <select name="credit_status" >
                <option value="">Please Credit Status</option>
                <option value="0">审核中</option>
                <option value="1">已完成</option>
            </select>
        </div>
        <div class="layui-inline" style="padding-left: 5px;">
            <input type="text" name="datetime" id="datetime" placeholder="Start Time _ End Time" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
            </div>
        </div>
    </div>
</form>
<div class="table-body">
    <table id="balanceTable" lay-filter="balanceTable"></table>
</div>
<script>
    layui.use(['form', 'laydate', 'table',], function () {
        var laydate = layui.laydate,
            form = layui.form,
            table = layui.table; //表格
        //时间插件
        laydate.render({
            elem: '#datetime',
            range: '_',
            format: 'yyyy-MM-dd'
        });
        var tableIn = table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            totalRow: true,
            method: 'post',
            url: "{:url('Cards/CreditLssClose')}",
            id: 'balanceTable',
            //where:{tran_token : $('#tran_token').val()},
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports'],
            cols: [[
                { type: 'numbers'},
                { field: 'option', title: 'Action', templet: function (d) {
                        var html = '';
                        html += '<a class="layui-btn layui-btn-xs credit_amount" data-id="' + d.id + '">手续费</a>';
                        html += '<a class="layui-btn layui-btn-xs credit_amount_user" data-id="' + d.id + '">手续费(+入账)</a>';
                        return html;
                    }, align: 'center', width: 200,
                },
                { field: 'username',  align: 'left', title: '会员',width: 180},
                { field: 'status', title: '卡状态', width:100 ,
                    templet:function (d) {
                        const status=   d.card_status;
                        var   html  =   '';
                        switch (status) {
                            case 1:
                                html = "<span style='color: green'>ACTIVE</span>";
                                break;
                            case 2:
                                html = "<span style='color: #6c757d'>SUSPENDED</span>";
                                break;
                            case 3:
                                html = "<span style='color: red'>CLOSED</span>";
                                break;
                            case 4:
                                html = "<span style='color: red'>Fraud</span>";
                                break;
                        }
                        return html;
                    }
                },
                { field: 'card_num', title: '卡号',width: 160,align:"left",totalRowText:'Total：', templet: function (d) {
                        const card_num = d.card_num;
                        var html = '<a style="color: #0e8df3;" ' +
                            'href="' + "{:url('cards/cardLog')}?card_num=" + card_num + '">' + card_num + '</a>';
                        return html;
                    }
                },

                { field: 'amount',  align: 'right', title: '退款金额($)',width: 120,
                    style:'color:#FF5722;font-weight:bold',totalRow: true},
                { field: 'server_amount',  align: 'right', title: '手续费($)',width: 110,
                    style:'font-weight:bold',totalRow: true,
                    templet: function (d) {
                        const server_amount = d.server_amount;
                        const card_num      = d.card_num;
                        if(server_amount != undefined){
                            var html = '<a style="color: #0e8df3;" ' +
                                'href="' + "{:url('balance/account')}?card_num=" + card_num + '">' + server_amount + '</a>';
                            return html;
                        }else{
                            return '-';
                        }

                    }
                },
                { field: 'ctime', align: 'center', title: '交易时间' ,width: 170},
                { align: 'center', title: '审核时间',width:170,
                    templet: function (d) {
                        const  utime = d.utime;
                        if(utime == null){
                            return '--';
                        }else{
                            return layui.util.toDateString(d.utime * 1000, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                },
                { field: 'shopping',  align: 'left', title: '商家'},
                { field: 'tran_token', align: 'center', title: 'tranToken'},
                { field: 'app_code', align: 'center', title: 'AppCode'},

            ]],
            page: true,
            limit: 20,
            limits: [20, 50, 100 ,500 ,1000],
        });
        form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //余额编辑
        $(document).on('click', '.credit_amount', function () {
            var id = $(this).attr('data-id');
            layer.confirm('您确定要操作么,此操作只收取退款手续费?', {
                title:'Window' , btn: ['confirm', 'cancel'], //按钮
            }, function () {
                JsPost("{:url('creditAmountClose')}", {id:id}, function(res){
                    if(res.code >0){
                        layer.msg(res.msg, { time: 1500 , icon:1}, function () {
                            tableIn.reload({
                                page:{
                                    curr :1
                                }
                            });
                        });
                    }else{
                        layer.msg(res.msg , {time:1500 , icon:2});
                    }
                })
            });
        });
        $(document).on('click', '.credit_amount_user', function () {
            var id = $(this).attr('data-id');
            layer.confirm('您确定要操作么,此操作收取退款手续费,并且退款金额会入账用户余额?', {
                title:'Window' , btn: ['confirm', 'cancel'], //按钮
            }, function () {
                JsPost("{:url('creditAmountClose')}", {id:id,user_amount:1}, function(res){
                    if(res.code >0){
                        layer.msg(res.msg, { time: 1500 , icon:1}, function () {
                            tableIn.reload({
                                page:{
                                    curr :1
                                }
                            });
                        });
                    }else{
                        layer.msg(res.msg , {time:1500 , icon:2});
                    }
                })
            });
        });
    });
</script>